<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>OA协同办公系统</title>
<link href="css/table.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/kindeditor/kindeditor-min.js"></script>
<script type="text/javascript" src="js/kindeditor/lang/zh_CN.js"></script>
<script type="text/javascript" src="js/openwindow.js"></script>
<script type="text/javascript">
var editor;
KindEditor.ready(function(K) {
	editor = K.create('textarea[name="content"]', {
		themeType : 'simple',
		resizeType : 1,
		allowPreviewEmoticons : false,
		allowImageUpload : false,
		items : [
			'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
			'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
			'insertunorderedlist', '|', 'emoticons', 'image', 'link','print','link','unlink']
		});
	});
	
	function selectUser(){
		var url="getGrouphome.action";
		openWindow(url,700,400);
	}
	
	function getOldValue(){
	  var array = document.getElementById("array").value;
	  return array;
	}
	
	function setValue(value){
	  document.getElementById("array").value = value;
	  var arr = eval(value);
	  var names = "";
	  var ids = "";
	  for(i=0;i<arr.length;i++){
	    ids =  ids + "," + arr[i].value;
	    names = names + "," + arr[i].name;
	  }
	  if(names.length>0){
	    names = names.substring(1);
	    ids =  ids.substring(1);
	  }
	  document.getElementById("names").value=names;
	  document.getElementById("ids").value=ids;
	}
	
	function addTemplate(){
		var content =editor.html();
		var name =$("#name").val();
		var note=$("#description").val()
		if(name=='null'||name==''){
			alert("请填写模板名称");
			return;
		}
		if(editor.isEmpty()){
			alert("请填写内容");
			return;
		}else if(content.length>2000){
			alert("正文不能超过2000个字符！");
			return;
		}
		
		$("#content").val($.trim(content));
		$.post("saveTemplate.action",$("form").serialize(),function(data){
		if(data=='success'){
			alert("添加成功");
		window.close();
		window.opener.location.href="templateList.action";
		}else{
		alert("添加失败");
		}
		});
		
	}
</script>
</head>
<body>
<table align="center" border="0" cellpadding="0" cellspacing="0" width="98%">
  <tbody>
  <tr>
    <td style="background: url('image/wsoa_window_002.gif');" width="1"></td>
    <td style="background: url('image/wsoa_window_002.gif');"><table border="0" cellpadding="0" cellspacing="0">
      <tbody><tr>
        <td align="center" style="background: url('image/wsoa_window_002.gif');" width="10"><img src="image/center_19.gif"></td>
        <td align="center" style="background: url('image/wsoa_window_002.gif');"></td>
        <td>个人办公 &gt; 工作汇报 &gt; 模板设置 &gt;<a href="templateSave.action"> 增加</a></td>
        </tr>
    </tbody>
    </table></td>
    <td style="background: url('image/wsoa_window_002.gif');" width="1"></td>
  </tr>
  <tr>
    <td style="background: url('image/wsoa_window_010.gif');"  width="1">&nbsp;</td>
    <td>
    <form action="" method="post" name="saveTemplateForm" id="saveTemplateForm">
    <input type="hidden" id="array" >
    <table style="margin-top: 10px">
    	<tr>
    		<td width="60px" headers="18px">模版名称：</td>
    		<td>
    			<input id="name" name="name" maxlength="50" title="最多不超过50个字符"  type="text" style="width: 99%;height:18px"  />
    		</td>
    	</tr>
    	<tr>
    		<td>适用范围：</td>
    		<td>
    		<textarea readonly="readonly" id="names" name="names" style="width:525px;height:auto;">${names }</textarea><br/>
    		<input type="hidden" id="ids" name="users" value="${users}">
    		<a href="javascript:selectUser()">添加联系人</a>&nbsp;<font style="font-size: 12px;color:red">默认不填则所有人都能使用</font></td></tr>
    	<tr>
    		<td>模版描述：</td>
    		<td>
    		<textarea name="description" onkeyup="textLength(this,200)" id="description" style="width: 100%;height:80px"></textarea>
    		</td>
    	</tr>
    	<tr>
    		<td colspan="2">
    			<textarea name="content" id="content" style="width:100%;height:300px;visibility:hidden;">${content}</textarea>
    		</td>
    	</tr>
    	<tr>
    		<td colspan="2">
    			<input class="button_04" type="button" value="保存退出" onclick="addTemplate()" />&nbsp;
    			<input class="button_02" type="reset" value="重置" />&nbsp;
    			<input class="button_02" type="button" value="退出" onclick="window.close();" />
    		</td>
    	</tr>
    </table>
    </form>
    <td style="background: url('image/wsoa_window_006.gif');"  width="1">&nbsp;</td></tr>
  <tr>
    <td height="1" width="1"><img src="image/wsoa_window_009.gif" height="16" width="14"></td>
    <td style="background: url('image/wsoa_window_008.gif');" height="1"></td>
    <td height="1" width="1"><img src="image/wsoa_window_007.gif" height="16" width="12"></td>
  </tr>
</tbody>
</table>
</body>
</html>